﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Splashscreen
{
    public partial class Splashscreen : UserControl, ISilverlightLoader
    {
        private SpinningGlobe _spinningGlobe;
        private ProgressBar _progress;

        public Splashscreen()
        {
            InitializeComponent();
        }

        public void initCallback(List<Uri> packageSourceList)
        {
        }

        public void downloadStartCallback(Uri packageSource)
        {
            _spinningGlobe = new SpinningGlobe();
            _spinningGlobe.SetValue(Grid.RowProperty, 0);
            LayoutRoot.Children.Add(_spinningGlobe);

            _progress = new ProgressBar();
            _progress.SetValue(Grid.RowProperty, 1);
            LayoutRoot.Children.Add(_progress);
        }

        public void downloadProgressCallback(Uri packageSource, DownloadProgressEventArgs eventArgs)
        {
            float percentageDownloadedAcurate = ((float)eventArgs.BytesReceived / eventArgs.TotalBytesToReceive) * 100;
            _progress.ProgressBarCtrl.Value = eventArgs.ProgressPercentage;
        }

        public void downloadCompleteCallback(Uri packageSource, DownloadCompleteEventArgs eventArgs)
        {
            XapUtil.setCurrentXapFile(packageSource);
        }
    }
}
